In the addon of the session, we counted the charging stations located within North-Rhine Westphalia (NRW). Still, we did not show how to get a point layer of NRW charging stations (“charger_nrw”).
Subset the data file yourself by relying on the spatial information of the filecharging_points_ger.csv and a polygon of NRW.
There are two ways to achieve this. How many chargers are located within
NRW?
charging_points_ger.csv (remember to adjust the crs) in the
./data folder and polygons of NRW. For the latter, you can
again use the osmdata syntax.
There are two functions you can explore: sf::st_join and
sf::st_intersection(). The default of
sf::st_join() will leave you with a ‘left-join’ and returns
a data object with all chargers and matching district information for
those which are located within NRW. You can reset the option to perform
an ‘inner-join’ and keep only the observation which lay within the
predefined area
(sf::st_join(x , y, join = "", left = FALSE)).
Did the operationalization of train station accessbility convince you? The INKAR data base offers another approach: Proportion of residents with max. 1000m linear distance to the nearest public transport stop in the district. We do have everything to create this indicator. You can run this code to load all the data you need. What is the mean share of residents with max. 1000m linear distance to the nearest train station in a 5km neighbourhood of our fake respondents?
nrw <-
osmdata::getbb(
"Nordrhein-Westfalen",
format_out = "sf_polygon"
) %>%
.$multipolygon %>%
sf::st_transform(3035)
set.seed(1234)
fake_coordinates <-
sf::st_sample(nrw, 1000) %>%
sf::st_sf() %>%
dplyr::mutate(
id_2 =
stringi::stri_rand_strings(10000, 10) %>%
sample(1000, replace = FALSE)
)
nrw_pt_trainstops <- sf::st_read("./data/nrw_pt_osmtrainstops.shp", crs = 3035)
inhabitants_ger <-
z11::z11_get_100m_attribute(Einwohner)
sf point layer of the raster object you can use
terra::as.points() %>% sf::st_as_sf(). To rasterize the
object you can use
terra::rast(vals = .$colname, resolution = 100).